<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library"
  exclude-result-prefixes="msxml umbraco.library"
  xmlns:fb="http://www.facebook.com/2008/fbml">

  <xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:param name="currentPage"/>
  <xsl:param name="MaxNoChars" select="100" />

  <xsl:variable name="recordsPerPage" select="3"/>
  <xsl:variable name="section"  select ="/macro/SectionName" />

  <!-- Root Node -->
  <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::root" />


  <xsl:template match="/">


    <!--
      =============================================================
      For Each child node of the currentpage
      =============================================================
      -->

    <xsl:for-each select="$rootNode/CWS_Master/EditorsDesk/EditorsDeskArticle [@isDoc and string(umbracoNaviHide) != '1']">

      <xsl:if test="position() mod 3 = 1">
        <xsl:text disable-output-escaping="yes">&lt;div class="clearleft"&gt;</xsl:text>
      </xsl:if>
      <xsl:call-template name="OneArticle" />
      <xsl:if test="position() mod 3 = 0 or position()=last()">
        <xsl:text disable-output-escaping="yes">&lt;/div&gt;</xsl:text>
      </xsl:if>
    </xsl:for-each>

  </xsl:template>

  <xsl:template name="OneArticle" >
    <div class="recent-excerpts">
      <h3>
        <xsl:value-of select="$section"/>
      </h3>
      <a href="{umbraco.library:NiceUrl(@id)}">
        <img class="HomeImage" src="{current()/articlePhoto}" alt="{@nodeName}"/>
      </a>
      <h3>
        <xsl:value-of select="@nodeName"/>
      </h3>
      <p>
        <!-- TODO: strip HTML & truncate -->
        <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(current()/bodyText), $MaxNoChars, '...')" />
      </p>
      <p>
        <a href="{umbraco.library:NiceUrl(@id)}" class="more-link">
          (More ...)
        </a>
      </p>
    </div>
  </xsl:template>

</xsl:stylesheet>